Dynamic experiments - multiple orientations

In [1]:
# Imports
import math as m
import numpy as np
import matplotlib.pyplot as plt
import holoviews as hv
import pylab as pl
from pylab import exp,cos,sin,pi,tan, pi
import pandas as pd
import seaborn as sb
import holoviews as hv
from IPython.display import SVG
import io
from PIL import Image
from random import random
import elastica as el
import elastica_neurons as en
from dynamics import *
%matplotlib inline
hv.notebook_extension()
/afs/inf.ed.ac.uk/user/s12/s1247380/Documents/HonoursProject/Python/venv/lib/python2.7/site-packages/IPython/html.py:14: ShimWarning: The `IPython.html` package has been deprecated. You should import from `notebook` instead. `IPython.html.widgets` has moved to `ipywidgets`.
  "`IPython.html.widgets` has moved to `ipywidgets`.", ShimWarning)
HoloViewsJS successfully loaded in this cell.
In [35]:
m = 11
n = 11
tau = 6
# Number of orientation selective neurons
nosn = 9
timesteps = 200
# for vonMises function
k = 0.25
A = 3


np.random.seed(67)
ac_orient4 = np.pi*np.random.rand(m,n)
ac_orient4[2:8,6] = np.random.rand(6)/5

oneColor()
visualField(ac_orient4)
Out[35]:
In [12]:
ac_orient4
Out[12]:
array([[ 1.71484284,  2.69817762,  2.15479511,  1.04172643,  0.18848905,
         1.21352744,  0.66963003,  2.92955604,  2.27080066,  0.14732595,
         2.58022413],
       [ 1.85941287,  0.791906  ,  0.98984262,  0.59011055,  1.10056245,
         0.80815213,  0.03491602,  1.28676025,  1.29513556,  0.13568153,
         3.00024861],
       [ 1.24934004,  1.66397091,  0.73140334,  0.96951105,  1.73408952,
         2.22574183,  0.1175148 ,  1.89100255,  1.26371058,  1.11504611,
         2.55777004],
       [ 0.93506948,  1.71095636,  3.02561201,  0.57615388,  2.28707109,
         2.3035416 ,  0.14540065,  3.04604549,  1.16409687,  2.22093082,
         0.86057868],
       [ 0.78239815,  0.95809899,  0.43621639,  3.06341366,  0.02642678,
         2.81006604,  0.00959217,  2.9123674 ,  1.25816911,  1.47168282,
         1.40569687],
       [ 2.85389934,  2.01783326,  0.75336632,  2.1247819 ,  1.34831604,
         0.70704899,  0.09155197,  1.42487525,  2.58206834,  2.00417221,
         3.13268737],
       [ 1.6552049 ,  0.76952077,  0.08935838,  2.16977943,  0.93122347,
         2.41899554,  0.02282052,  1.45771731,  0.0389983 ,  0.49179738,
         0.52935394],
       [ 0.74658207,  1.97620463,  0.5254549 ,  1.12718581,  2.51679544,
         2.49572624,  0.13336024,  0.74791809,  1.4629788 ,  2.98369483,
         1.65532888],
       [ 1.018921  ,  0.30875137,  0.66839516,  0.06571758,  2.10468959,
         0.73059991,  2.4940054 ,  1.03864741,  0.08470291,  3.03181929,
         2.97800739],
       [ 2.75441919,  2.20397515,  0.54860654,  2.52761559,  1.21551017,
         2.23464441,  0.90930209,  0.30201863,  2.09600163,  2.87601205,
         0.3599478 ],
       [ 0.08116513,  2.84669804,  2.69328832,  2.38289311,  1.46737196,
         0.40793906,  1.70346316,  0.56964894,  1.28891233,  2.05058872,
         0.26738287]])
In [5]:
np.array((2,2,2))
Out[5]:
array([2, 2, 2])
In [36]:
results, rs, direction, magnitude = runExperiment('el',m,n,nosn,ac_orient4,timesteps,tau,vis=False,el_factor=-0.01,torus=True)
In [3]:
results, rs, direction, magnitude = runExperiment('el',m,n,nosn,ac_orient4,timesteps,tau,vis=True,el_factor=-0.01,E0=4)
In [35]:
results
Out[35]:
In [37]:
visualFieldMagnitude(direction[:,:,199],magnitude[:,:,199]/8)
Out[37]:
In [43]:
a = magnitude[:,:,199]
a
#a[2:8,6]
Out[43]:
array([[ 7.12693343,  7.12156255,  6.99594099,  7.09896701,  7.2492164 ,
         7.03788281,  7.29797365,  7.16974068,  6.79042766,  7.31816327,
         6.83687638],
       [ 7.03981549,  7.06464788,  7.05806459,  7.15096498,  7.08746491,
         7.14560551,  7.26716704,  7.07390283,  7.11558974,  7.24537827,
         7.06329595],
       [ 7.04576424,  6.99308934,  7.14865764,  7.06549127,  6.94496922,
         6.77528519,  7.18404333,  6.84100166,  7.09545703,  7.2195853 ,
         6.83627958],
       [ 7.0800274 ,  7.04125598,  7.01570037,  7.11654624,  6.76787679,
         6.73799533,  7.13901501,  7.10411662,  7.09027385,  6.81653354,
         7.24471911],
       [ 7.11263194,  7.08851717,  7.11188772,  7.07257358,  7.14473863,
         6.99536398,  7.15662009,  6.97169403,  7.04817029,  7.10851965,
         7.22889407],
       [ 6.97804783,  6.86638438,  7.12945235,  6.80397524,  7.00620217,
         7.12273447,  7.09124618,  7.05870765,  6.82021923,  6.91117608,
         7.11520495],
       [ 7.0118457 ,  7.14907494,  7.06815564,  6.7424639 ,  7.04638413,
         6.79092819,  7.13606727,  7.0440881 ,  7.15230881,  7.11607532,
         7.1096896 ],
       [ 7.233876  ,  6.78446024,  7.1427335 ,  7.07335232,  6.7947129 ,
         6.81764983,  7.09410217,  7.1110364 ,  7.06407072,  7.03310524,
         7.09456549],
       [ 7.27786823,  7.26663075,  7.22295362,  7.13356842,  6.81538345,
         7.15186689,  6.86856338,  7.12178717,  7.14499625,  7.10096185,
         7.06263455],
       [ 7.01836737,  6.72539667,  7.23629661,  6.87316894,  7.03639021,
         6.78400653,  7.07901625,  7.22005545,  6.94652218,  7.12785057,
         7.11260811],
       [ 7.30619385,  7.09581924,  7.01440062,  6.88436127,  7.0015989 ,
         7.26764685,  6.9240541 ,  7.15957352,  6.97898926,  7.03967508,
         7.08069964]])
In [40]:
magnitude[2:8,6,199]
Out[40]:
array([ 4.790271  ,  5.01998342,  5.01583804,  4.19488552,  4.2127222 ,
        4.31026607])
In [19]:
ac_orient2 = np.pi/2*np.ones((m,n))
ac_orient2[5,5] = 0
timesteps = 50

visualField(ac_orient2)
Out[19]:
In [46]:
results, rs, direction, magnitude = runExperiment('el',m,n,nosn,ac_orient2,timesteps,tau,vis=True,el_factor=-0.01)
In [25]:
results, rs, direction, magnitude = runExperiment('el',m,n,nosn,ac_orient2,timesteps,tau,vis=False,el_factor=-0.01,torus=True)
In [47]:
results
Out[47]:
In [27]:
visualFieldMagnitude(direction[:,:,49],magnitude[:,:,49]/3)
Out[27]:
In [49]:
visualFieldMagnitude(direction[:,:,49],magnitude[:,:,49]/3)
Out[49]:
In [32]:
magnitude[:,:,49]
Out[32]:
array([[ 1.27707388,  0.70922309,  0.46517206,  0.34536366,  0.2913287 ,
         0.28233809,  0.2913287 ,  0.34536366,  0.46517206,  0.70922309,
         1.27707388],
       [ 2.16588866,  1.5809445 ,  1.39707361,  1.30558709,  1.25525414,
         1.23454476,  1.25525414,  1.30558709,  1.39707361,  1.5809445 ,
         2.16588866],
       [ 2.56541826,  1.90697361,  1.77360516,  1.74630227,  1.71990983,
         1.68137479,  1.71990983,  1.74630227,  1.77360516,  1.90697361,
         2.56541826],
       [ 2.68682647,  1.94737703,  1.80116261,  1.81268215,  1.84304384,
         1.77317733,  1.84304384,  1.81268215,  1.80116261,  1.94737703,
         2.68682647],
       [ 2.6418702 ,  1.8263973 ,  1.62703312,  1.62706153,  1.75857974,
         1.61756461,  1.75857974,  1.62706153,  1.62703312,  1.8263973 ,
         2.6418702 ],
       [ 2.57967778,  1.70950496,  1.43103939,  1.27894946,  1.07245931,
         2.18315005,  1.07245931,  1.27894946,  1.43103939,  1.70950496,
         2.57967778],
       [ 2.6418702 ,  1.8263973 ,  1.62703312,  1.62706153,  1.75857974,
         1.61756461,  1.75857974,  1.62706153,  1.62703312,  1.8263973 ,
         2.6418702 ],
       [ 2.68682647,  1.94737703,  1.80116261,  1.81268215,  1.84304384,
         1.77317733,  1.84304384,  1.81268215,  1.80116261,  1.94737703,
         2.68682647],
       [ 2.56541826,  1.90697361,  1.77360516,  1.74630227,  1.71990983,
         1.68137479,  1.71990983,  1.74630227,  1.77360516,  1.90697361,
         2.56541826],
       [ 2.16588866,  1.5809445 ,  1.39707361,  1.30558709,  1.25525414,
         1.23454476,  1.25525414,  1.30558709,  1.39707361,  1.5809445 ,
         2.16588866],
       [ 1.27707388,  0.70922309,  0.46517206,  0.34536366,  0.2913287 ,
         0.28233809,  0.2913287 ,  0.34536366,  0.46517206,  0.70922309,
         1.27707388]])
In [6]:
ac_orient3 = np.pi/2*np.ones((m,n))
for i in range(m):
    ac_orient3[i,i] = 3*np.pi/4
visualField(ac_orient3)
Out[6]:
In [51]:
results, rs, direction, magnitude = runExperiment('el',m,n,nosn,ac_orient3,timesteps,tau,vis=True,el_factor=-0.01)
In [13]:
results, rs, direction, magnitude = runExperiment('el',m,n,nosn,ac_orient3,timesteps,tau,vis=False,el_factor=-0.1,torus=True)
In [14]:
visualFieldMagnitude(direction[:,:,49],magnitude[:,:,49]/8)
Out[14]:
In [35]:
visualFieldMagnitude(direction[:,:,49],magnitude[:,:,49]/3)
Out[35]:
In [12]:
magnitude
Out[12]:
array([[[ 1.48251386,  2.67253381,  3.62064653, ...,  7.35237369,
          7.35237369,  7.35237369],
        [ 1.48220139,  2.68903529,  3.66198569, ...,  7.77990807,
          7.77990807,  7.77990807],
        [ 1.48220139,  2.68709828,  3.65663532, ...,  7.72103588,
          7.72103588,  7.72103588],
        ..., 
        [ 1.48220139,  2.68705184,  3.65654853, ...,  7.72276085,
          7.72276085,  7.72276085],
        [ 1.48220139,  2.68928779,  3.66235209, ...,  7.78523911,
          7.78523911,  7.78523911],
        [ 1.48220139,  2.69212275,  3.66971372, ...,  7.86554326,
          7.86554326,  7.86554326]],

       [[ 1.48220139,  2.69210837,  3.67032318, ...,  7.86936589,
          7.86936589,  7.86936589],
        [ 1.48251386,  2.66882213,  3.61037715, ...,  7.24029218,
          7.24029218,  7.24029218],
        [ 1.48220139,  2.68687727,  3.65599147, ...,  7.71032942,
          7.71032942,  7.71032942],
        ..., 
        [ 1.48220139,  2.68752049,  3.6577407 , ...,  7.73526089,
          7.73526089,  7.73526089],
        [ 1.48220139,  2.68984121,  3.66375767, ...,  7.80017407,
          7.80017407,  7.80017407],
        [ 1.48220139,  2.6928913 ,  3.67167141, ...,  7.88617394,
          7.88617394,  7.88617394]],

       [[ 1.48220139,  2.69223187,  3.67055754, ...,  7.87006798,
          7.87006798,  7.87006798],
        [ 1.48220139,  2.68911525,  3.66205345, ...,  7.77523798,
          7.77523798,  7.77523798],
        [ 1.48251386,  2.6654095 ,  3.60142648, ...,  7.14535369,
          7.14535369,  7.14535369],
        ..., 
        [ 1.48220139,  2.68769042,  3.65816031, ...,  7.73910306,
          7.73910306,  7.73910306],
        [ 1.48220139,  2.69015746,  3.66455828, ...,  7.80869029,
          7.80869029,  7.80869029],
        [ 1.48220139,  2.69325231,  3.67257922, ...,  7.89576176,
          7.89576176,  7.89576176]],

       ..., 
       [[ 1.48220139,  2.69325231,  3.67257922, ...,  7.89576176,
          7.89576176,  7.89576176],
        [ 1.48220139,  2.69015746,  3.66455828, ...,  7.80869029,
          7.80869029,  7.80869029],
        [ 1.48220139,  2.68769042,  3.65816031, ...,  7.73910306,
          7.73910306,  7.73910306],
        ..., 
        [ 1.48251386,  2.6654095 ,  3.60142648, ...,  7.14535369,
          7.14535369,  7.14535369],
        [ 1.48220139,  2.68911525,  3.66205345, ...,  7.77523798,
          7.77523798,  7.77523798],
        [ 1.48220139,  2.69223187,  3.67055754, ...,  7.87006798,
          7.87006798,  7.87006798]],

       [[ 1.48220139,  2.6928913 ,  3.67167141, ...,  7.88617394,
          7.88617394,  7.88617394],
        [ 1.48220139,  2.68984121,  3.66375767, ...,  7.80017407,
          7.80017407,  7.80017407],
        [ 1.48220139,  2.68752049,  3.6577407 , ...,  7.73526089,
          7.73526089,  7.73526089],
        ..., 
        [ 1.48220139,  2.68687727,  3.65599147, ...,  7.71032942,
          7.71032942,  7.71032942],
        [ 1.48251386,  2.66882213,  3.61037715, ...,  7.24029218,
          7.24029218,  7.24029218],
        [ 1.48220139,  2.69210837,  3.67032318, ...,  7.86936589,
          7.86936589,  7.86936589]],

       [[ 1.48220139,  2.69212275,  3.66971372, ...,  7.86554326,
          7.86554326,  7.86554326],
        [ 1.48220139,  2.68928779,  3.66235209, ...,  7.78523911,
          7.78523911,  7.78523911],
        [ 1.48220139,  2.68705184,  3.65654853, ...,  7.72276085,
          7.72276085,  7.72276085],
        ..., 
        [ 1.48220139,  2.68709828,  3.65663532, ...,  7.72103588,
          7.72103588,  7.72103588],
        [ 1.48220139,  2.68903529,  3.66198569, ...,  7.77990807,
          7.77990807,  7.77990807],
        [ 1.48251386,  2.67253381,  3.62064653, ...,  7.35237369,
          7.35237369,  7.35237369]]])
In [55]:
t = np.arange(0,timesteps,1)

plotOneField((0,0),t,nosn,rs)
Out[55]:
In [16]:
ac_orient4 = np.pi/2*np.ones((m,n))
timesteps = 50
ac_orient4[5,5] = 0
visualField(ac_orient4)
Out[16]:
In [28]:
results, rs, direction, magnitude = runExperiment('el',m,n,nosn,ac_orient4,timesteps,tau,vis=False,el_factor=-0.01,torus=True)
In [34]:
magnitude[:,:,49]
Out[34]:
array([[ 7.91494089,  7.82844724,  7.76336658,  7.7208577 ,  7.69518924,
         7.68900421,  7.69518924,  7.7208577 ,  7.76336658,  7.82844724,
         7.91494089],
       [ 7.92113537,  7.8332441 ,  7.76686058,  7.72237268,  7.69182522,
         7.68362891,  7.69182522,  7.72237268,  7.76686058,  7.8332441 ,
         7.92113537],
       [ 7.92269467,  7.83401681,  7.76505553,  7.71744433,  7.6862038 ,
         7.67733556,  7.6862038 ,  7.71744433,  7.76505553,  7.83401681,
         7.92269467],
       [ 7.92169103,  7.83089173,  7.76156159,  7.7145926 ,  7.68311419,
         7.67359353,  7.68311419,  7.7145926 ,  7.76156159,  7.83089173,
         7.92169103],
       [ 7.91976721,  7.83027397,  7.7611238 ,  7.71481361,  7.68339918,
         7.67308969,  7.68339918,  7.71481361,  7.7611238 ,  7.83027397,
         7.91976721],
       [ 7.92054581,  7.8316974 ,  7.76352598,  7.71687308,  7.68587998,
         5.85644468,  7.68587998,  7.71687308,  7.76352598,  7.8316974 ,
         7.92054581],
       [ 7.91976721,  7.83027397,  7.7611238 ,  7.71481361,  7.68339918,
         7.67308969,  7.68339918,  7.71481361,  7.7611238 ,  7.83027397,
         7.91976721],
       [ 7.92169103,  7.83089173,  7.76156159,  7.7145926 ,  7.68311419,
         7.67359353,  7.68311419,  7.7145926 ,  7.76156159,  7.83089173,
         7.92169103],
       [ 7.92269467,  7.83401681,  7.76505553,  7.71744433,  7.6862038 ,
         7.67733556,  7.6862038 ,  7.71744433,  7.76505553,  7.83401681,
         7.92269467],
       [ 7.92113537,  7.8332441 ,  7.76686058,  7.72237268,  7.69182522,
         7.68362891,  7.69182522,  7.72237268,  7.76686058,  7.8332441 ,
         7.92113537],
       [ 7.91494089,  7.82844724,  7.76336658,  7.7208577 ,  7.69518924,
         7.68900421,  7.69518924,  7.7208577 ,  7.76336658,  7.82844724,
         7.91494089]])
In [29]:
visualFieldMagnitude(direction[:,:,49],magnitude[:,:,49])
Out[29]:
In [18]:
visualFieldMagnitude(direction[:,:,49],magnitude[:,:,49]/8)
Out[18]:
In [11]:
showWeightsFile('el11x11x9,0_torus.npy')
In [2]:
matrix, distance = elasticaMatrix(6,6,5,torus=True)
In [3]:
showWeights(matrix)
In [27]:
np.array(([1,2],[2,3]))
Out[27]:
array([[1, 2],
       [2, 3]])